package com.itlong.cloud.controller.logger;

import com.itlong.cloud.POJO.DTO.operate.OperateRobotLogGetPageDTO;
import com.itlong.cloud.POJO.PO.OperateReleaseLogPO;
import com.itlong.cloud.POJO.VO.MessageVO;
import com.itlong.cloud.POJO.VO.operate.OperateRobotLogGetPageVO;
import com.itlong.cloud.abstracts.BaseController;
import com.itlong.cloud.annotation.AuthAccessRequired;
import com.itlong.cloud.enumerate.ecode.BaseErrorCodeEnum;
import com.itlong.cloud.noncore.operate.IOperateRobotLogServiceClient;
import com.itlong.cloud.thrown.DataAccessException;
import com.itlong.cloud.utils.network.http.HttpProtocolUtil;
import com.itlong.cloud.utils.page.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;

/**
 * <desc>
 *      运营-机器人操作日志管理控制器
 * </desc>
 *
 * @createDate 2018/10/12
 */
@RestController
@RequestMapping("/logger/robotLog")
public class OperateRobotLogController extends BaseController {

    @Autowired
    private IOperateRobotLogServiceClient iOperateRobotLogServiceClient;

    /**
     * <desc>
     *      分页查询机器人操作日志
     * </desc>
     *
     * @param operateRobotLogGetPageDTO 查询参数
     * @return 标准格式化响应结果
     * @author wangzhi
     * @createDate 2018/10/12
     */
    @ResponseBody
    @AuthAccessRequired
    @PostMapping("getPage")
    public Object getRobotLogByPage(OperateRobotLogGetPageDTO operateRobotLogGetPageDTO){
        try {
            HttpServletRequest request=((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
            operateRobotLogGetPageDTO= HttpProtocolUtil.parseRequestParamToDTO(OperateRobotLogGetPageDTO.class,request);
            if (operateRobotLogGetPageDTO == null) {
                return new MessageVO(BaseErrorCodeEnum.NOT_PARAM.getErrorCode());
            }
            Page<OperateRobotLogGetPageVO> operateRobotLogGetPageVOPage = iOperateRobotLogServiceClient.getRobotLogByPage(operateRobotLogGetPageDTO);
            return new MessageVO(BaseErrorCodeEnum.SUCCESS.getErrorCode(),operateRobotLogGetPageVOPage);
        } catch (Exception e) {
            throw new DataAccessException("【运营-机器人操作日志管理】分页查询机器人操作日志失败",e);
        }
    }

}
